package com.sanben.tag.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sanben.common.web.domain.Result;
import java.util.List;

import com.sanben.tag.entity.Tag;
import com.sanben.tag.data.dto.TagDto;
import com.sanben.tag.data.vo.TagVo;
import com.sanben.tag.data.req.TagReq;
import com.sanben.tag.service.ITagService;

/**
 * @author cyh
 * @description: 标签表 控制器
 * @date: 2020-08-18
 */
@RestController
@RequestMapping("tag")
@Api(tags = "标签表相关接口")
public class TagController {

    @Autowired
	private ITagService tagService;

	@GetMapping("/page")
	@ApiOperation(value = "分页", notes = "传入tag")
	public Result<IPage<TagVo>> page(TagReq req) {
		IPage<TagVo> pages = tagService.page(req);
		return Result.data(pages);
	}

	@GetMapping("/list")
	@ApiOperation(value = "不分页")
	public Result<List<Tag>> list() {
		List<Tag> list = tagService.lists();
		return Result.data(list);
	}

	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入id")
	public Result<Tag> detail(@PathVariable Integer id) {
	    Tag detail = tagService.detail(id);
		return Result.data(detail);
	}

	@PostMapping
	@ApiOperation(value = "新增", notes = "传入tag")
	public Result save(@RequestBody TagDto dto) {
		return Result.data(tagService.save(dto));
	}

	@PutMapping
	@ApiOperation(value = "修改", notes = "传入tag")
	public Result update(@RequestBody TagDto dto) {
		return Result.data(tagService.updateById(dto));
	}

	@DeleteMapping("/{ids}")
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public Result remove(@PathVariable List<Integer> ids) {
		return Result.data(tagService.deleteLogic(ids));
	}

}
